﻿using EFCore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.IDAL
{
   public interface IBaseDal<T> where T:class
   {
       #region 对象的添加、修改、删除操作

       bool Insert(T t);
       bool Delete(object id);
       bool Delete(T t);
       bool Update(T t,object key);

       #endregion

       #region 返回实体类操作

       T FindById(object id);
       T FindSingle(Expression<Func<T, bool>> match);

       #endregion


       #region 返回集合的接口

       IQueryable<T> GetQueryable();
       /// <summary>
       /// 根据条件查询返回记录
       /// </summary>
       /// <param name="match">查询条件</param>
       /// <param name="sortPropertyName">排序表达式</param>
       /// <param name="isDescending">false为升序，true为降序</param>
       /// <returns></returns>
       IQueryable<T> GetQueryable<TKey>(Expression<Func<T, bool>> match, Expression<Func<T, TKey>> order, bool isDescending = true);
       /// <summary>
       /// 根据条件返回集合
       /// </summary>
       /// <param name="match">条件表达式</param>
       /// <returns></returns>
       IQueryable<T> Find(Expression<Func<T, bool>> match);
       /// <summary>
       /// 根据条件返回集合
       /// </summary>
       /// <param name="match">查询条件</param>
       /// <param name="sortPropertyName">排序表达式</param>
       /// <param name="isDescending">false为升序，true为降序</param>
       /// <returns></returns>
       IQueryable<T> Find<TKey>(Expression<Func<T, bool>> match, Expression<Func<T, TKey>> order, bool isDescending = true);
       /// <summary>

       #endregion

       #region
       /// <summary>
       /// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
       /// </summary>
       /// <param name="match">条件表达式</param>
       /// <param name="info">分页实体</param>
       /// <param name="orderByProperty">排序表达式</param>
       /// <param name="isDescending">如果为true则为降序，否则为升序</param>
       /// <returns>指定对象的集合</returns>
       ICollection<T> FindWithPager(Expression<Func<T, bool>> match, PagerInfo info);

       /// <summary>
       /// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
       /// </summary>
       /// <param name="match">条件表达式</param>
       /// <param name="info">分页实体</param>
       /// <param name="orderByProperty">排序表达式</param>
       /// <param name="isDescending">如果为true则为降序，否则为升序</param>
       /// <returns>指定对象的集合</returns>
       ICollection<T> FindWithPager<TKey>(Expression<Func<T, bool>> match, PagerInfo info, Expression<Func<T, TKey>> orderByProperty, bool isDescending = true);
       #endregion

       #region 直接执行SQL的辅助方法

       List<TResult> RunSql<TResult>(string sql, params object[] pamrs);

       #endregion
   }
}
